const upload = async function(vm, {
	// #ifdef APP-PLUS || H5
	files,
	// #endif
	// #ifdef H5
	file,
	// #endif
	// #ifdef MP-ALIPAY
	fileType,
	// #endif
	filePath,
	name,
	formData
}) {
	return new Promise((resolve, reject) => {
		uni.showLoading({
			mask: true,
			title: '上传中'
		});
		let data = {
			url: vm.vuex_config.upload.uploadurl,
			header: {
				token: vm.vuex_token || '',
				uid: vm.vuex_user.id || 0
			},
			name: 'file',
			complete: function() {
				uni.hideLoading();
			},
			success: uploadFileRes => {
				try {
					var res = uploadFileRes.data;
					if (uni.$u.test.jsonString(res)) {
						resolve(JSON.parse(res))
					}
					if (uni.$u.test.object(res)) {
						resolve(res)
					}
				} catch (e) {
					reject(uploadFileRes.data);
				}
			},
			fail: (e) => {
				reject(e);
			}
		};
		// #ifdef H5
		//有文件对象，一般是H5
		if (file) {
			data.file = file;
		}
		// #endif
		//文件路径
		if (filePath) {
			data.filePath = filePath;
		}
		let isObj = uni.$u.test.object(vm.vuex_config.upload.multipart);
		if (isObj && formData) {
			data.formData = Object.assign(formData, vm.vuex_config.upload.multipart);
		} else if (isObj) {
			data.formData = vm.vuex_config.upload.multipart;
		} else if (formData) {
			data.formData = formData;
		}
		uni.uploadFile(data);
	})

}
const install = (Vue, vm) => {
	vm.$api.getConfig = async (params = {}) => await uni.$u.http.get('/addons/career/api.v1.common/init', params);
	vm.$api.getUserInfo = async (params = {}) => await uni.$u.http.get('/addons/career/api.v1.user/index', params);
	vm.$api.getUserProfile = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.user/profile', params);
	vm.$api.goUserLogout = async (params = {}) => await uni.$u.http.get('/addons/career/api.v1.user/logout', params);
	vm.$api.goUserSignout = async (params = {}) => await uni.$u.http.get('/addons/career/api.v1.user/signout', params);
	vm.$api.goLogin = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/login', params);
	vm.$api.mobilelogin = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/mobilelogin', params);
	vm.$api.goRegister = async (params = {}) => await uni.$u.post('/addons/career/api.v1.login/register', params);
	vm.$api.goResetpwd = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/resetpwd', params);
	vm.$api.gowxLogin = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/wxLogin', params);
	vm.$api.goWechatMobileLogin = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/wechatMobileLogin', params);
	vm.$api.goAppLogin = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/appLogin', params);
	vm.$api.getWechatOpenid = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/getWechatOpenid', params);
	vm.$api.getWechatMobile = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.login/getWechatMobile', params);
	vm.$api.goUpload = async (params = {}) => await upload(vm, params);
	vm.$api.getSmsSend = async (params = {}) => await uni.$u.http.post('/addons/career/api.v1.sms/send', params);
	vm.$api.dictionaries  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.common/dictionaries',params);
	vm.$api.page  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.page/detail',params);
	vm.$api.getTraineeList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.archives/trainee',params);
	vm.$api.getTraineeDetail  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.archives/traineeDetail',params);
	vm.$api.getPolicyList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.archives/policy',params);
	vm.$api.getPolicyDetail  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.archives/policyDetail',params);
	vm.$api.getCourseList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.course/index',params);
	vm.$api.getCollegeList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.common/college',params);
	vm.$api.getMajorList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.common/major',params);
	vm.$api.getClassesList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.classes/index',params);
	vm.$api.getClassesDetail  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.classes/detail',params);
	vm.$api.entryClasses  = async(params = {}) => await uni.$u.http.post('/addons/career/api.v1.classes_order/store',params);//技能培训报名
	vm.$api.buyClasses  = async(params = {}) => await uni.$u.http.post('/addons/career/api.v1.classes_order/buy',params);//购买
	vm.$api.getCourseDetail  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.course/detail',params);
	vm.$api.getCourseChapter  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.course/chapter',params);
	vm.$api.getCommentList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.comment/index',params);
	vm.$api.sendComment  = async(params = {}) => await uni.$u.http.post('/addons/career/api.v1.comment/store',params);
	vm.$api.watchCourseVideo  = async(params = {}) => await uni.$u.http.post('/addons/career/api.v1.course_video/watch',params);
	vm.$api.postCollect  = async(params = {}) => await uni.$u.http.post('/addons/career/api.v1.course/collect',params);
	vm.$api.getMyCourseCollect  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.user/courseCollect',params);
	vm.$api.getMyCourseRecord  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.user/courseRecord',params);
	vm.$api.getMyClassesOrder  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.classes_order/index',params);
	vm.$api.getQuestionList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.question/index',params);
	vm.$api.getWrongQuestionList  = async(params = {}) => await uni.$u.http.post('/addons/career/api.v1.question/wrongList',params);
	vm.$api.delWrongAnswer  = async(params = {}) => await uni.$u.http.delete('/addons/career/api.v1.question/delWrong',params);
	vm.$api.submitPaper  = async(params = {}) => await uni.$u.http.post('/addons/career/api.v1.paper/store',params);
	vm.$api.getPaperList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.paper/index',params);
	vm.$api.getExamCategory  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.exam_category/index',params);
	
	vm.$api.addressResolution  = async(params = {}) => await uni.$u.http.get('/addons/tenant/api.v1.common/addressResolution',params);
	vm.$api.getMessageList  = async(params = {}) => await uni.$u.http.get('/addons/career/api.v1.message/index',params);
	vm.$api.markReadMessage  = async(params = {}) => await uni.$u.http.put('/addons/career/api.v1.message/markRead',params);
	
}

export default {
	install
}
